<?php

namespace App\Http\Controllers;

use App\Http\LoginService;
use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function login(Request $request, LoginService $loginService)
    {
        $passport = $loginService->applyPasswordToken($request->username, $request->password);
        if (empty($passport['success'])) return response(['success' => false, 'message' => $passport['message']], 415);
        return response()->json(['success' => true, 'data' => ['token' => $passport['token']]]);
    }

    public function logout(
        LoginService $loginService
    )
    {
        $result = $loginService->logout('api');
        return response()->json(['success' => true, 'message' => '退出成功']);
    }
}
